package com.buddies.lottery.utils;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;

import com.blankj.utilcode.util.ToastUtils;
import com.tencent.bugly.crashreport.CrashReport;

public class SystemUtils {

    /**
     * Get Mobile Type
     *
     * @return
     */
    public static String getMobileType() {
        return Build.MANUFACTURER;
    }

    public static void jumpAppDetailSettings(Context context) {
        try {
            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.fromParts("package", context.getPackageName(), null));
            context.startActivity(intent);
        } catch (Throwable e1) {
            CrashReport.postCatchedException(e1);
            try {
                Intent intent = new Intent(Settings.ACTION_SETTINGS);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setData(Uri.fromParts("package", context.getPackageName(), null));
                context.startActivity(intent);
            } catch (Throwable e2) {
                CrashReport.postCatchedException(e2);
                ToastUtils.showShort("请前往设置打开权限");
            }
        }
    }

    public static void openBrowser(Context context, String url) {
        try {
            Intent intent = new Intent();
            intent.setClassName("com.UCMobile","com.uc.browser.InnerUCMobile");

            // 优先使用UC浏览器
            PackageManager pm = context.getPackageManager();
            if (pm.resolveActivity(intent, 0) == null) {
                intent.setComponent(null); // 没有找到UC浏览器，清除设置
            }

            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            context.startActivity(intent);
        } catch (Exception e) {
            CrashReport.postCatchedException(e);
        }
    }

}
